package com.chen.controller;


import com.chen.dto.ResponData;
import com.chen.entity.User;
import com.chen.general.Constans;
import com.chen.general.StateCode;
import com.chen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/login")
public class UserController {


    @Autowired
    private UserService userService;

    @RequestMapping("loginUser")
    public ResponData Login(
            @RequestParam(name = "email", required = false) String email,
            @RequestParam(name = "password", required = false) String password) {
        User user = this.userService.queryUser(email, password);
        if (user == null) {
            return new ResponData(Constans.LOGIN_ERROR, StateCode.LOGIN_ERROR);
        } else {
            return new ResponData(Constans.LOGIN_SUCCESS, StateCode.SUCCEED_CODE, user);
        }
    }


    @RequestMapping("exitUser")
    public ResponData exitUser(
            @RequestParam(name = "email") String email) {
        boolean b = this.userService.exitUser(email);
        if (b) {
            return new ResponData(Constans.SUCCESS_MES, StateCode.SUCCEED_CODE);
        } else {
            return new ResponData(Constans.ERROR_MESS, StateCode.ERROR_CODE);
        }
    }
}
